/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dk.rofl.items;

import rofl.Utils;

/**
 *
 * @author Jeppe
 */
public class Weapon extends Equipment {

    private int minDamage;
    private int maxDamage;

    public Weapon(String weaponName, int minDamage, int maxDamage, int itemLevel, int itemQuality) {
        super(GameItem.TYPE_WEAPON, weaponName, itemLevel, itemQuality);
        this.minDamage = minDamage;
        this.maxDamage = maxDamage;
    }

    public static Weapon generateWeapon(int itemLevel) {
        Weapon w = generateWeapon(itemLevel, Equipment.generateItemQuality());
        return w;
    }

    public static Weapon generateWeapon(int itemLevel, int itemQuality) {
        if(itemLevel < 1) {
            itemLevel = 1;
        }
        
        double minDmg;
        double maxDmg;
        
        maxDmg = (double)itemLevel * 4.0 + (double)itemLevel * (double)Utils.rnd().nextInt(2);
        minDmg = maxDmg * 0.25;
        
        double staBonus = ((double)itemLevel * (double)Utils.rnd().nextInt(itemLevel)+1) / 2.0;
        double strBonus = ((double)itemLevel * (double)Utils.rnd().nextInt(itemLevel)+1) / 2.0;

        staBonus += Utils.rnd().nextInt(itemLevel);
        strBonus += Utils.rnd().nextInt(itemLevel);

        switch (itemQuality) {
            case Equipment.QUALITY_CRUDE:
                maxDmg = maxDmg * 1.0;
                minDmg = maxDmg * 0.25;
                staBonus = 0.0;
                strBonus = 0.0;
                break;
            case Equipment.QUALITY_NORMAL:
                maxDmg = maxDmg * 1.5;
                minDmg = maxDmg * 0.5;
                staBonus = 0.0;
                strBonus = 0.0;
                break;
            case Equipment.QUALITY_MAGIC:
                maxDmg = maxDmg * 2.0;
                minDmg = maxDmg * 0.75;
                if(staBonus < 1.0) {
                    staBonus = 1.0;
                }
                if(strBonus < 1.0) {
                    strBonus = 1.0;
                }
                break;
            case Equipment.QUALITY_SUPERIOR:
                maxDmg = maxDmg * 2.5;
                minDmg = maxDmg * 0.85;
                staBonus = staBonus * 2.0;
                strBonus = strBonus * 2.0;
                if(staBonus < 1.0) {
                    staBonus = 1.0;
                }
                if(strBonus < 1.0) {
                    strBonus = 1.0;
                }
                break;
            case Equipment.QUALITY_EPIC:
                maxDmg = maxDmg * 3.5;
                minDmg = maxDmg * 0.95;
                staBonus = staBonus * 3.0;
                strBonus = strBonus * 3.0;
                if(staBonus < 1.0) {
                    staBonus = 1.0;
                }
                if(strBonus < 1.0) {
                    strBonus = 1.0;
                }
                break;
        }

        if( minDmg < 1.0 ) {
            minDmg = 1.0;
        }
        
        Weapon w = new Weapon(generatePrefix(itemQuality)+generateName()+generatePostfix(itemQuality), (int)minDmg, (int)maxDmg, itemLevel, itemQuality);
        w.setStaminaBonus((int)staBonus);
        w.setStrengthBonus((int)strBonus);
        return w;
    }

    public static String generateName() {
        String s = "";

        int r = Utils.rnd().nextInt(5);
        switch (r) {
            case 0:
                s = "Sword";
                break;
            case 1:
                s = "Axe";
                break;
            case 2:
                s = "Dagger";
                break;
            case 3:
                s = "Spear";
                break;
            case 4:
                s = "Club";
                break;
        }
        return s;
    }


    public int getMaxDamage() {
        return maxDamage;
    }

    public void setMaxDamage(int MaxDamage) {
        this.maxDamage = MaxDamage;
    }

    public int getMinDamage() {
        return minDamage;
    }

    public void setMinDamage(int MinDamage) {
        this.minDamage = MinDamage;
    }
}
